﻿//
//
var gCountryId = 804;
var gCountryName = "Украина";
var gCityId = 23;
var gCityName = "Киев";

function Options() {
    var self = this;

    this.country = {};
    this.city = {};

    this.load = function() {
        self.country = {
            id: readOption("country_id", gCountryId),
            name: readOption("country_name", gCountryName)
        };
        self.city = {
            id: readOption("city_id", gCityId),
            name: readOption("city_name", gCityName)
        };
    }

    this.save = function() {
        saveOption("country_id", self.country.id);
        saveOption("country_name", self.country.name);
        saveOption("city_id", self.city.id);
        saveOption("city_name", self.city.name);
    }

    function readOption(optionName, tag) {
        var value = System.Gadget.Settings.read(optionName);

        if (value == "") {
            return tag;
        }
        return value;
    }

    function saveOption(optionName, value, tag) {
        System.Gadget.Settings.write(optionName, value ? value : tag);
    }
}